package com.ruoyi.web.controller.nongjt;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.nongjt.domain.NjtUserInfo;

import com.ruoyi.nongjt.domain.NjtUserInfo;
import com.ruoyi.nongjt.service.NjtUserInfoService;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @author yang
 */
@RestController
@RequestMapping("/nongjt/userInfo")
public class NjtUserInfoController extends BaseController {
    @Autowired
    private NjtUserInfoService njtUserInfoService;

    @GetMapping("/list")
    public TableDataInfo list(NjtUserInfo njtUserInfo){
        startPage();
        List<NjtUserInfo> list = njtUserInfoService.getNjtUserInfoList(njtUserInfo);
        return getDataTable(list);
    }
    @PutMapping
    public AjaxResult update(@RequestBody NjtUserInfo njtUserInfo){
        int rows = njtUserInfoService.updateNjtUserInfo(njtUserInfo);
        return toAjax(rows);
    }

    @DeleteMapping("deleteByUserId")
    public AjaxResult delete(@RequestParam Integer userId){
        int rows = njtUserInfoService.deleteNjtUserInfoById(userId);
        return toAjax(rows);
    }

    @PostMapping("/export")
    public void export(NjtUserInfo njtUserInfo, HttpServletResponse response){
        List<NjtUserInfo> list = njtUserInfoService.getNjtUserInfoList(njtUserInfo);
        ExcelUtil<NjtUserInfo> util = new ExcelUtil<NjtUserInfo>(NjtUserInfo.class);
        util.exportExcel(response, list, "用户注册信息");
    }


}
